<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function makeCounter() {
        let count = 0;
        return function () {
          return ++count;
        };
      }

      let counter = makeCounter();
      console.log(counter()); // 1
      console.log(counter()); // 2

      let counter2 = makeCounter(); // 初始化新count=0
      console.log(counter2()); // 1
      console.log(counter2()); // 2
      //-----------
      console.log("end");
    </script>
  </body>
</html>
